package com.csi.service.impl;

import com.csi.dao.EmployDao;
import com.csi.dao.impl.EmployDaoImpl;
import com.csi.domain.Employ;
import com.csi.service.EmployService;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class EmployServiceImpl implements EmployService {
    @Override
    public Employ select(int employNumber, String employPassword)  {
        Employ employ=null;
        EmployDao employDao=new EmployDaoImpl();
        try {
            employ=employDao.select(employNumber,employPassword);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return employ;
    }

    @Override
    public int add(Employ employ)  {
        EmployDao employDao=new EmployDaoImpl();
        int i=0;
        try {
            i=employDao.add(employ);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return i;
    }

    @Override
    public int delete(int employId) {
        EmployDao employDao=new EmployDaoImpl();
        int i=0;
        try {
            i=employDao.delete(employId);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return i;
    }

    @Override
    public int update(Employ employ)  {
        EmployDao employDao=new EmployDaoImpl();
        int i=0;
        try {
            i=employDao.update(employ);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return i;
    }

    @Override
    public List<Employ> list() {
        EmployDao employDao =new EmployDaoImpl();
        List<Employ> employs =new ArrayList<>();

        try {
            employs =employDao.list();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return employs;
    }
}
